package com.kun.util;

import com.kun.entity.SysUser;
import org.springframework.core.NamedThreadLocal;

/**
 * @author kun.li
 */
public class LoginUserContext {

    private static final ThreadLocal<SysUser> CONTEXT = new NamedThreadLocal<>("loginUser");

    public static void setUser(SysUser user) {
        CONTEXT.set(user);
    }

    public static SysUser getUser() {
        return CONTEXT.get() == null ? new SysUser() : CONTEXT.get();
    }

    public static void clear() {
        CONTEXT.remove();
    }
}
